package chaoyue.study.health;

import chaoyue.study.component.MyComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

/**
 * 健康监控类
 * Indicator后缀是固定的，前面表示要监控的组件
 */
@Component
public class MyComponentIndicator extends AbstractHealthIndicator {
    @Autowired
    private MyComponent myComponent;

    /**
     * 自定义健康检查的逻辑
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) {
        if (myComponent.checkHealth()) {
            builder.up().withDetail("msg","活的好好的").build();
        } else {
            builder.down().withDetail("msg","凉透了").build();
        }
    }
}
